% Add Tools to Path
addpath('../Tools');

% Benchmark to measure computation time of our method

% Choose data
% -> Source data
[filename, pathname] = uigetfile('*.mat', 'Select the mat file of the source mesh');
dataName = strcat(pathname, filename);
% -> Target data
[filename, pathname] = uigetfile('*.mat', 'Select the mat file of the source mesh');
targetDataName = strcat(pathname, filename);

load (dataName);
nV = size(vertices, 1);
nT = size(triangles, 1);

% Choose number of samples
nSamples = 100;

sampling = randsample(nV, nSamples);

elapsedTimeSource.Gf = zeros(nSamples, 1);
elapsedTimeSource.Gm = zeros(nSamples, 1);
elapsedTimeTarget.Gf = zeros(nSamples, 1);
elapsedTimeTarget.MatchAndTransfer = zeros(nSamples, 1);

for i = 1 : nSamples
    % 1. on the Source
    cd '../Source';
    
    [elapsedTimeGf, elapsedTimeGm] = main( dataName, sampling(i) );
    elapsedTimeSource.Gf(i) = elapsedTimeGf;
    elapsedTimeSource.Gm(i) = elapsedTimeGm;
       
    copyfile 'dataForTrg.mat' '../Target';    
    
    % 2. on the Target
    cd '../Target';           
    
    [userTri, userTriW, cost, elapsedTimeGf, elapsedTimeMatchAndTransfer] = main( dataName, 'dataForTrg.mat' );
    elapsedTimeTarget.Gf(i) = elapsedTimeGf;
    elapsedTimeTarget.MatchAndTransfer(i) = elapsedTimeMatchAndTransfer;       

end % for samples

% Display results
disp('Source full grapg elapsed time:');
mean( elapsedTimeSource.Gf )
disp('Source minimal graph elapsed time:');
mean( elapsedTimeSource.Gm )
disp('Target full graph:');
mean( elapsedTimeTarget.Gf )
disp('Target match and transfer:');
mean( elapsedTimeTarget.MatchAndTransfer )


